﻿using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using StockholmsStad.Web.UI.Class.Interfaces;
using StockholmsStad.Web.UI.UIServiceReference;

namespace StockholmsStad.Web.UI.Registrering
{
    /// <summary>
    /// Tredjesida för registreringen. Innehåller sammanställning över
    /// parets registrering
    /// </summary>
    public partial class Registration3_Summary : UserControl, IRegistration3_Summary
    {
        /// <summary>
        /// Controller för de berömda "ändra"-länkarna
        /// </summary>
        public IViewController ViewController { get; set; }

        #region IRegistration3_Summary Members

        /// <summary>
        /// Sätter person1
        /// </summary>
        public Person Person1
        {
            set { ucRegistration1.Person = value; }
        }

        /// <summary>
        /// Sätter person2
        /// </summary>
        public Person Person2
        {
            set { ucRegistration2.Person = value; }
        }

        /// <summary>
        /// Sätter kontaktinformationen
        /// </summary>
        public ContactPerson Contact
        {
            set
            {
                txtContactEmail.Text = value.Email;
                txtContactName.Text = value.FirstNames + " " + value.LastName;
                txtContactPhone.Text = value.Telephone;
            }
        }

        /// <summary>
        /// Sätter ceremoniinformation
        /// </summary>
        public Ceremony Ceremony
        {
            set
            {
                txtCeremonyLanguage.Text = value.CeremonyLanguage.Name;
                txtCertificateLanguage.Text = value.CertificateLanguage.Name;
                txtSpecialNeeds.Text = value.SpecialNeeds.Length == 0 ? "" : value.SpecialNeeds[0].Name;
            }
        }

        #endregion

        /// <summary>
        /// Körs när sidan laddas
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Page_Load(object sender, EventArgs e)
        {
            /*
            btnChangePerson1.CommandName = IViewControllerViews.Person1View.ToString();
            btnChangePerson2.CommandName = IViewControllerViews.Person2View.ToString();
            btnChangeContact.CommandName = IViewControllerViews.ContactView.ToString();
            btnChangeCeremony.CommandName = IViewControllerViews.CeremonyView.ToString();
             */
        }

        /// <summary>
        /// Körs när användaren trycker på någon av 'ändra'-länkarna
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void changeView_Click(object sender, EventArgs e)
        {
            var webControl = (LinkButton) sender;
            if (ViewController != null)
            {
                if (webControl.CommandName.Equals(IViewControllerViews.Person1View.ToString()))
                    ViewController.ChangeToPerson1View();
                else if (webControl.CommandName.Equals(IViewControllerViews.Person2View.ToString()))
                    ViewController.ChangeToPerson2View();
                else if (webControl.CommandName.Equals(IViewControllerViews.ContactView.ToString()))
                    ViewController.ChangeToContactView();
                else if (webControl.CommandName.Equals(IViewControllerViews.CeremonyView.ToString()))
                    ViewController.ChangeToCeremonyView();
                else
                    throw new Exception("Illegal state, CommandName: " + webControl.CommandName);
            }
        }
    }
}